package org.teremail.message;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class MultipartEntity implements Multipart {

    private final ContentHeaders contentHeader;
    private List<Entity> parts;
    private final String preamble;
    private final String epilogue;
    private final String id;

    public MultipartEntity(String id, ContentHeaders contentHeader, String preamble, 
            List<Entity> parts, String epilogue) {
        this.id = id;
        this.contentHeader = contentHeader;
        this.preamble = preamble;
        this.parts = Collections.unmodifiableList(parts);
        this.epilogue = epilogue;
    }

    public MultipartEntity(ContentHeaders contentHeader, String preamble, 
            List<Entity> parts, String epilogue) {
        this(Entity.UNSAVED_ID, contentHeader, preamble, parts, epilogue);
    }
    
    public String getId() {
        return id;
    }
    
    public ContentHeaders getContentHeader() {
        return contentHeader;
    }

    public String getEpilogue() {
        return epilogue;
    }

    public String getPreamble() {
        return preamble;
    }

    public Iterator<Entity> iterator() {
        return parts.iterator();
    }
    
    public void accept(EntityVisitor v) {
        v.visitMultipartEntity(this);
    }

    public EntityType getType() {
        return EntityType.MULTIPART_ENTITY;
    }

}
